struct ListNode* deleteDuplicates(struct ListNode* head){
    if(head==NULL){
        return head;
    }
    struct ListNode *dummy=malloc(sizeof(struct ListNode));
    dummy->next=head;
    struct ListNode*pre=dummy,*p=pre->next,*q;
    int x;
    if(pre!=NULL&&pre->next!=NULL){
        q=p->next;
    }else{
        return dummy->next;
    }
    while(p!=NULL){
        if(q!=NULL && p->val==q->val){
            x=p->val;
            pre->next=q->next;
            free(p);
            free(q);
            p=pre->next;
            q=p!=NULL?p->next:NULL;
        }
        else if(p->val==x){
            pre->next=p->next;
            free(p);
            p=pre->next;
            q=p!=NULL?p->next:NULL;
        }else{
            pre=pre->next;
            p=p->next;
            q=q!=NULL?q->next:NULL;
        }
    }
    return dummy->next;
}